package com.warren.blog.controller;

import com.warren.blog.mapper.BookMapper;
import com.warren.blog.pojo.Book;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author warren
 */
@RestController
@RequestMapping("book")
@Api("book mybatis")
public class BookController {
    @Autowired()
    private BookMapper bookMapper;


    @GetMapping("/queryBookList")
    public List<Book> queryBookList() {
        List<Book> books= bookMapper.queryBookList();
        return books;
    }

    @GetMapping("deleteBook/{id}")
    public int deleteBook(@PathVariable("id") int id) {
        int row = bookMapper.deleteBook(id);
        return row;
    }

    @PostMapping("addBook")
    public int addBook(@RequestBody Book book) {
        System.out.println(book);
        int row = 1;
        bookMapper.addBook(book);
        return row;
    }

    @GetMapping("queryBookById/{id}")
    public Book queryBookById(@PathVariable("id") int id) {
        Book book = bookMapper.queryBookById(id);
        return book;
    }

    @PostMapping("updateBook")
    public int updateBook(@RequestBody Book book) {
        System.out.println(book);
        return bookMapper.updateBook(book);
    }

}
